<template>
  <div class="goodsDetail">
    <div>
      <div class="mt20">
        <span class="main_active">{{ translate('标签标识号') }}：</span>
        <el-input
          v-model="formInfo.UUID"
          class="w400"
          :disabled="true"
          type="text"
        />
      </div>
      <div class="mt20">
        <span class="main_active">{{ translate('MAC地址') }}：</span>
        <el-input v-model="formInfo.ESLCode" class="w400" :disabled="true" />
      </div>
      <div class="mt20">
        <span class="main_active">{{ translate('基站标识号') }}：</span>
        <el-select v-model="formInfo.BSID" class="w400" placeholder="Select">
          <el-option
            v-for="item in BaseStockData"
            :key="item.BSID"
            :label="'[' + item.BSID + ']' + item.BSName"
            :value="item.BSID"
          />
        </el-select>
      </div>
      <!-- <div class="mt20">
        <span class="main_active">{{ translate('基站名称') }}：</span>
        <el-input v-model="formInfo.BSName" class="w400" type="text" />
      </div> -->
      <!-- <div class="mt20">
        <span class="main_active">{{ translate('标签标识号') }}：</span>
        <el-input v-model="formInfo.UUID" class="w400" type="text" />
      </div> -->
      <div class="mt20">
        <span class="main_active">{{ translate('密钥') }}：</span>
        <el-input v-model="formInfo.ESLCodeOld" class="w400" type="text" />
      </div>
      <div class="mt20">
        <span class="main_active">{{ translate('屏幕尺寸') }}：</span>
        <el-select v-model="formInfo.LCDType" class="w400" placeholder="Select">
          <el-option
            v-for="item in LCDData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div class="mt20">
        <span class="main_active">{{ translate('标签模板') }}：</span>
        <el-select
          v-model="formInfo.ESLTypeID"
          class="w400"
          placeholder="Select"
        >
          <el-option
            v-for="item in modelData"
            :key="item.ETCode"
            :label="item.ETName"
            :value="item.ETCode"
            @click="changename(item)"
          />
        </el-select>
      </div>
      <div class="mt20 goods">
        <span class="main_active">{{ translate('物资名称') }}：</span>
        <el-input v-model="formInfo.shopename" class="w400" :disabled="true" />
        <el-button
          class="button"
          size="small"
          type="primary"
          @click="ProductsData1()"
        >
          {{ translate('查询') }}
        </el-button>
      </div>
      <div class="mt20">
        <span class="main_active">{{ translate('条形码') }}：</span>
        <el-input
          v-model="formInfo.ESLCode2"
          class="w400"
          :placeholder="translate('条形码')"
        />
      </div>
      <div class="mt20">
        <span class="main_active">{{ translate('硬件版本') }}：</span>
        <el-input
          v-model="formInfo.Version"
          class="w400"
          :placeholder="translate('硬件版本')"
        />
      </div>
      <!-- <div class="mt20">
        <span class="main_active">{{ translate('备注') }}：</span>
        <el-input
          v-model="formInfo.Remark"
          class="w400"
          :placeholder="translate('备注')"
        />
      </div> -->
      <div class="mt20">
        <span class="main_active">{{ translate('状态') }}：</span>
        <el-switch
          v-model="formInfo.Status"
          :active-value="1"
          :inactive-value="0"
        />
      </div>
    </div>
    <el-dialog
      v-model="dialogChiled"
      :title="translate('物资列表')"
      width="650px"
      @close="closeFn"
    >
      <div style="padding-bottom: 10px">
        <span class="color_494949 ft12 pr5">{{ translate('物资名称') }}：</span>
        <el-input
          v-model="searchChild"
          class="w164 mr10"
          :placeholder="translate('请输入关键字')"
        />
        <span class="color_494949 ft12 pr5">
            {{ translate('物资编码') }}：
          </span>
          <el-input
            v-model="seachCode"
            class="w164 mr10"
            :placeholder="translate('请输入物资编码')"
        />
      </div>
      <div>
        <div class="mb10">
          <span class="color_494949 ft12 pr5">{{ translate('单位') }}：</span>
          <el-input
            v-model="searchWHUnit"
            class="w164 mr10"
            :placeholder="translate('请输入单位')"
          />
          <span class="color_494949 ft12 pr5">
            {{ translate('存放地点') }}：
          </span>
          <el-input
            v-model="searchStorageLocation"
            class="w164 mr10"
            :placeholder="translate('请输入存放地点')"
          />
          <el-button class="settingBtn mr10" type="primary" @click="ProductsData1">
          {{ translate('查询') }}
        </el-button>
        </div>
        <el-table
          border
          :data="productData"
          height="400"
          style="width: 750px"
          @row-click="singleElection"
        >
          <el-table-column width="55">
            <template #default="{ row }">
              <el-radio-group v-model="productNo" @change="changeproduct(row)">
                <el-radio :label="row.Code" />
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column :label="translate('商品编码')" prop="Code" />
          <el-table-column :label="translate('商品名称')" prop="Name" />
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            :current-page="pageNo"
            :layout="layout"
            :page-size="pageSize"
            :total="total"
            @current-change="handleCurrentchiled"
            @size-change="handleSizechiled"
          />
        </div>
      </div>
      <template #footer>
        <el-button @click="dialogChiled = false">
          {{ translate('取消') }}
        </el-button>
        <el-button type="primary" @click="submitChiled">
          {{ translate('确定') }}
        </el-button>
      </template>
    </el-dialog>
    <el-dialog
      v-model="dialogChiled1"
      :title="translate('物资列表')"
      width="800px"
      @close="closeFn"
    >
    <div style="padding-bottom: 10px">
        <span class="color_494949 ft12 pr5">{{ translate('物资名称') }}：</span>
        <el-input
          v-model="searchChild"
          class="w164 mr10"
          :placeholder="translate('请输入关键字')"
        />
        <span class="color_494949 ft12 pr5">
            {{ translate('物资编码') }}：
          </span>
          <el-input
            v-model="seachCode"
            class="w164"
            :placeholder="translate('请输入物资编码')"
        />
      </div>
      <div>
        <div class="mb10">
          <span class="color_494949 ft12 pr5">{{ translate('领料单位') }}：</span>
          <el-select
            v-model="searchWHUnit"
            class="w164"
            :placeholder="translate('请选择')"
          >
            <el-option
              v-for="item in supplierdata"
              :key="item.FullName"
              :label="item.FullName"
              :value="item.FullName"
            />
        </el-select>
          <span class="color_494949 ft12 pr5">
            {{ translate('存放地点') }}：
          </span>
          <el-input
            v-model="searchStorageLocation"
            class="w164"
            :placeholder="translate('请输入存放地点')"
          />
        </div>
        <div class="mb10">
          <span class="color_494949 ft12 pr5">{{ translate('库位') }}：</span>
          <el-input
            v-model="wsCode"
            class="w164 mr10"
            :placeholder="translate('请输入库位')"
          />
          <span class="color_494949 ft12 pr5">
            {{ translate('批次号') }}：
          </span>
          <el-input
            v-model="batchNo"
            class="w164 mr10"
            :placeholder="translate('请输入批次号')"
          />
          <el-button class="settingBtn mr10" type="primary" @click="ProductsData1">
          {{ translate('查询') }}
        </el-button>
        </div>
        <el-table
          border
          :data="productData"
          height="400"
          style="width: 750px"
          @row-click="singleElection"
        >
          <el-table-column width="55">
            <template #default="{ row }">
              <el-radio-group v-model="productNo" @change="changeproduct(row)">
                <el-radio :label="row.ISID" />
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column :label="translate('仓库单位')" prop="WHUnit" />
          <el-table-column :label="translate('物资编码')" prop="ItemCode" />
          <el-table-column :label="translate('物资类型')" prop="Owner" />
          <el-table-column :label="translate('物资名称')" prop="ItemName" />
          <el-table-column :label="translate('单位')" prop="ItemUnit" />
          <el-table-column :label="translate('规格')" prop="ItemSpec" />
          <el-table-column :label="translate('库位')" prop="WSCode" />
          <el-table-column :label="translate('库存')" prop="StockQty" />
          <el-table-column :label="translate('批次号')" prop="BatchNo" />
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            :current-page="pageNo"
            :layout="layout"
            :page-size="pageSize"
            :total="total"
            @current-change="handleCurrentchiled"
            @size-change="handleSizechiled"
          />
        </div>
      </div>
      <template #footer>
        <el-button @click="dialogChiled1 = false">
          {{ translate('取消') }}
        </el-button>
        <el-button type="primary" @click="submitChiled1">
          {{ translate('确定') }}
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script>
  import { getPageData } from '@/api/tag'
  import { ProductsData } from '@/api/eslstock'
  import { getItemList } from '@/api/supItem'
  import { WmsGetPageData02 } from '@/api/form'
  import { BaseGetPageData } from '@/api/item'
  import { translate } from '@/i18n'
  export default {
    name: 'Detail',
    components: {},
    props: {
      form: {
        type: Object,
        default: () => {
          return {}
        },
      },
      basestockdata: {
        type: Array,
        default: () => {
          return []
        },
      },
      dialoginfo: {
        type: Boolean,
        default: false,
      },
    },
    emits: ['deletedchild'],
    data() {
      return {
        translate: translate,
        formInfo: this.form,
        BaseStockData: this.basestockdata,
        dialogChiled: false,
        dialogChiled1: false,
        modelData: [],
        productData: [],
        wsCode: '',
        batchNo: '',
        pageNo: 1,
        pageSize: 10,
        total: 0,
        productNo: '',
        searchChild: '',
        seachCode: '',
        searchWHUnit: '',
        searchStorageLocation: '',
        selectProduct: {},
        supplierdata: [],
        layout: 'total, sizes, prev, pager, next, jumper',
        LCDData: [
          // {
          //   label: '212*104',
          //   value: '00',
          // },
          // {
          //   label: '200*200',
          //   value: '01',
          // },
          // {
          //   label: '296*152',
          //   value: '02',
          // },
          // {
          //   label: '250*122',
          //   value: '03',
          // },
          // {
          //   label: '880*528',
          //   value: '04',
          // },
          {
             label: '4.2(300*400)',
             value: '4.2',
          },
          {
             label: '2.9(296*128)',
             value: '2.9',
          },
          {
             label: '2.13(250*128)',
             value: '2.13',
          },
          {
             label: '7.5(480*800)',
             value: '7.5',
          },
          {
             label: '2.66(296*152)',
             value: '2.66',
          },
          {
             label: '1.54(152*152)',
             value: '1.54',
          },
          {
             label: '5.8(480*648)',
             value: '5.8',
          }
        ],
      }
    },
    watch: {
      form(val) {
        this.formInfo = val
      },
      dialoginfo: {
        handler(val) {
          console.log(val)
          if (val) {
            this.getPageData(val)
          }
        },
        immediate: true,
      },
      'formInfo.LCDType': {
        handler(val) {
          if (val) {
            this.getPageData(val)
          }
        },
      },
    },
    methods: {
      async BaseGetPageData() {
        const params = {
          pageNo: 1,
          pageSize: 100,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: '',
        }
        const data = await BaseGetPageData(params)
        this.supplierdata = data.data.rows
        this.supplierdata.unshift({
          FullName: '全部'
        })
      },
      //分页条数切换
      handleSizechiled(val) {
        this.pageSize = val
        this.ProductsData1()
        // this.ProductsData()
      },
      //分页切换
      handleCurrentchiled(val) {
        this.pageNo = val
        this.ProductsData1()
        // this.ProductsData()
      },
      singleElection(e) {
        this.selectProduct = e
        this.productNo = e.ISID
      },
      changeproduct(e) {
        this.selectProduct = e
      },
      changename(val) {
        console.log(val)
        this.formInfo.ESLTypeName = val.ETName
      },
      submitChiled() {
        if (this.selectProduct) {
          this.formInfo.shopename = `[${this.selectProduct.Code}]${this.selectProduct.Name}`
          this.formInfo.PCode = this.selectProduct.Code
          this.formInfo.PName = this.selectProduct.Name
          this.dialogChiled = false
        }
      },
      submitChiled1() {
        if (this.selectProduct) {
          this.formInfo.shopename = `[${this.selectProduct.ItemCode}]${this.selectProduct.ItemName}`
          this.formInfo.PCode = this.selectProduct.ISID
          this.formInfo.PName = this.selectProduct.ItemName
          this.dialogChiled1 = false
        }
      },
      async ProductsData() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'Name',
              value: this.searchChild,
              displayType: 'like',
            },
          ]),
          export: false,
          value: '',
        }
        const data = await ProductsData(params)
        this.productData = data.data.rows
        this.total = data.data.total
        this.dialogChiled = true
      },
      async ProductsData1() {
        this.BaseGetPageData()
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'ItemName',
              value: this.searchChild,
              displayType: 'like',
            },
            {
              name: 'WHUnit',
              value: this.searchWHUnit === '全部'?'':this.searchWHUnit,
              displayType: 'like',
            },
            {
              name: 'StorageLocation',
              value: this.searchStorageLocation,
              displayType: 'like',
            },
            {
              name: 'ItemCode',
              value: this.seachCode,
              displayType: 'like',
            },
            {
              name: 'WSCode',
              value: this.wsCode,
              displayType: 'like',
            },
            {
              name: 'BatchNo',
              value: this.batchNo,
              displayType: 'like',
            },
          ]),
          export: false,
          value: '',
          openid:'绑定标签'
        }
        const data = await WmsGetPageData02(params)
        this.productData = data.data.rows
        this.total = data.data.total
        this.dialogChiled1 = true
      },
      async getPageData() {
        console.log(this.formInfo.LCDType)
        const params = {
          pageNo: 1,
          pageSize: 20,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'LCDType',
              value:
                this.formInfo.LCDType === '-1' ? '' : this.formInfo.LCDType,
              displayType: 'like',
            },
          ]),
          export: true,
          value: '',
        }
        const data = await getPageData(params)
        this.modelData = data.data.rows
        if (data.data.rows.length <= 0) {
          this.formInfo.ESLTypeID = ''
          this.formInfo.ESLTypeName = ''
        }
      },
    },
  }
</script>
<style lang="scss" scoped>
  .goodsDetail {
    height: 400px;
  }
  .flex_align {
    display: flex;
    align-items: center;
  }
  .tableDetail {
    padding: 10px;
    .button-add {
      text-align: end;
      padding: 10px;
    }
  }
  .main_active {
    display: inline-block;
    width: 120px;
    text-align: right;
  }
  .mr20 {
    margin-right: 20px;
  }

  .w400 {
    width: 400px !important;
  }
  .mt20 {
    margin-top: 10px;
  }
  .mr10 {
    margin-right: 10px;
  }
  .w320 {
    width: 320px;
  }
  .goods {
    position: relative;

    .button {
      position: absolute;
      right: 40px;
      top: 4px;
    }
  }
  .w164 {
    width: 164px !important;
  }
  .mt10 {
    margin-top: 10px;
  }
  .mb10 {
    margin-bottom: 10px;
  }
  .color_494949 {
    width: 85px;
    display: inline-block;
    text-align: right;
  }
  ::v-deep .el-scrollbar__wrap {
    overflow-x: auto;
    height: calc(100% + 20px); //多出来的20px是横向滚动条默认的样式
  }
  ::v-deep .el-scrollbar .el-scrollbar__wrap .el-scrollbar__view {
    white-space: nowrap;
    display: inline-block;
  }
  ::v-deep .el-table--scrollable-x .el-table__body-wrapper {
    overflow-x: hidden;
  }
  ::v-deep input[type='number']::-webkit-inner-spin-button,
  ::v-deep input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
  }
  ::v-deep .el-radio__label {
    display: none;
  }
</style>
